package com.zwl.sjzmanagement.controller;

import com.atguigu.tingshu.common.result.Result;
import com.zwl.model.Materials;
import com.zwl.sjzmanagement.service.RoomCardService;
import com.zwl.vo.RoomCardContainersVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("api/roomCard")
class RoomCardController {

    @Autowired
    private RoomCardService roomCardService;

    //http://localhost:8002/api/roomCard/roomCardList
    @GetMapping("/roomCardList")
    public Result roomCardList() {
        Map<String, List<RoomCardContainersVo>> map = roomCardService.roomCardList();
        return Result.ok(map);
    }


//    http://localhost:8001/api/roomCard/roomCardAddOrUpdate
    @PostMapping("/roomCardAddOrUpdate")
    public Result roomCardAddOrUpdate(@RequestBody RoomCardContainersVo roomCardContainersVo) {

        roomCardService.roomCardAddOrUpdate(roomCardContainersVo);
        return Result.ok();
    }

//    http://localhost:8001/api/roomCard/roomCardDelById
    @DeleteMapping("/roomCardDelById/{id}")
    public Result roomCardDelById(@PathVariable Integer id) {

        roomCardService.deleteRCById(id);

        return Result.ok();

    }

    @PostMapping("/roomCardBatchDelById")
    public Result roomCardBatchDelById(@RequestBody List<Integer> ids) {

        //根据id判断，相同则执行跟新操作
        roomCardService.BatchdeleteRCById(ids);

        return Result.ok();

    }


    @GetMapping("/getRoomCardById/{id}")
    public Result getRoomCardById(@PathVariable Integer id) {

        RoomCardContainersVo roomCardContainersVo = roomCardService.getRoomCardVoById(id);
        return Result.ok(roomCardContainersVo);

    }
}
